package mytest.controller;

import org.json.JSONArray;

import mytest.util.Response;
import test.service.ServiceUser;
import test.testcase.dao.UserDao;
import test.testcase.dao.projectDao;
import test.user.user;
import test.utils.JsonResult;

public class base {
	
	public static Response check(String username, String projectid) {
		String userName = username.split("\\|")[0];
		String token = username.split("\\|")[1];
		user user = ServiceUser.getUserByUserName(userName);
		JsonResult result = UserDao.getToken(userName, token);
		Response response = new Response();
		if (result.read("data[0]").toJsonObject() == null) {
			response.setRetCodeFalse();
			response.setRetMessage("未登录");
			return response;
		}else {
			result = projectDao.getList(user.getUserid());
			JSONArray array = result.read("data").toJsonArray();
			for (int i = 0; i < array.length(); i++) {
				if (array.getJSONObject(i).getString("id").equals(projectid)) {
					return null;
				}
			}
			return response.setFalse("无项目权限");
		}
	}
	
	

}
